/**
 * Created by yangfan on 2016/11/11,
 */
define(['config/appregister','business/careerPlan/services/httpServices'],function(app,httpService){
    app.filter('filterNull',function(){
        return function(input){
        //    var ret = input ;
            if(toString.call(input) == '[object Null]'){
                return  '暂无翻译数据'
            }else{
                return input.toName
            }
        }
    });
    app.directive("uiTranslate",function($sce){
        return {
            templateUrl:"app/business/home/directives/templates/translate.html",
            link:function(scope,element,attrs){
                scope.isShowTranslate = false;
                scope.leav=function(){
                	scope.isShowTranslate = false;
                    scope.data = '';
                    scope.sceTranslate = '';
                };
                scope.$watch("isShowTranslate",function(newValue,oldValue){
                    if(newValue == true&&newValue!=oldValue){
                        var screenWidth = window.screen.availWidth;
                        var divWidth = $(".translate-window")[0].scrollWidth;
                        var a =  $(".translate-window").css("left",(screenWidth-divWidth)/2);
                    }
                });
                scope.clickTranslateBtn = function(){
                    scope.isShowTranslate = !scope.isShowTranslate
                };
                scope.translate = function(){
                    scope.result =  $sce.trustAsHtml('');
                    scope.sceTranslate = '';
                    var text = $("#translateModel").text();
                    if(text==''){
                        alert('翻译内容不能为空');
                        return;
                    }
                    var req = {
                        type:"GET",
                        uri:"get",
                        data:{
                            byName:text
                        }
                    };
                    httpService.getTranslate(req).success(function(response){
                        scope.$apply(function(){
                            if(response.data == null ) return ;
                            scope.result = $sce.trustAsHtml( response.data.toName);
                            scope.sceTranslate = $sce.trustAsHtml(response.data.translate) ;
                        })
                    })

                }

            }
        }
    })
});
